<template>
    <div>
        <Form ref="formInline" :model="formInline"  inline>
            <FormItem prop="department_name">
                <Input type="text" v-model="formInline.department_name" placeholder="单位名称" clearable>
                </Input>
            </FormItem>
            <FormItem prop="monthly">
                <DatePicker v-model="formInline.monthly" type="month" :placeholder="yf" style="width: 200px"></DatePicker>
            </FormItem>
            <FormItem prop="company">
                <Select v-model="formInline.company" style="width: 200px" clearable placeholder="单位类型">
                    <Option value="机关">机关</Option>
                    <Option value="事业">事业</Option>
                    <Option value="企业">企业</Option>
                    <Option value="其他">其他</Option>
                </Select>
            </FormItem>
            <FormItem>
                <Button type="success" @click="search()">搜索</Button>
            </FormItem>
            <FormItem>
                <Button type="primary"  @click="exportData"><Icon type="ios-download-outline"></Icon>导出</Button>
            </FormItem>
        </Form>
        <Table :columns="columns11" :data="data10" border show-summary>
            <template slot-scope="{ row}" slot="excel_impor">
                <Icon type="md-download" size="24" @click="download(row)" v-if="row.excel_impor !=='暂无链接可下载'" />
            </template>
            <template slot-scope="{ row}" slot="data_file">
                <Icon type="md-download" size="24" @click="downloadf(row)" v-if="row.data_file !=='暂无链接可下载'" />
            </template>
            <template slot-scope="{ row}" slot="action">
                <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">查看</Button>
            </template>
        </Table>
        <Page :total="params.totalRecord" show-sizer :page-size="params.pageSize" style="float: right;margin-top: 20px"
              show-total @on-change="pageAction" @on-page-size-change="pSizeChange"/>
    </div>
</template>

<script>
import { getZlShiZhiList } from '@/api/user'
export default {

  name: 'test',

  data () {
    return {
      yf: '',
      month: '',
      formInline: {
        department_name: '',
        monthly: '',
        company: ''
      },
      columns11: [
        {
          title: '序号列',
          type: 'index',
          align: 'center',
          width: 80
        },
        {
          title: '单位',
          key: 'department_name',
          align: 'center',
          width: 200
        },
        {
          title: '本单位调度情况',
          align: 'center',
          children: [
            {
              title: '三方专班人数合计',
              key: 'company_special_class',
              align: 'center',
              width: 200
            },
            {
              title: '本单位内部调度次数',
              key: 'company_num',
              align: 'center',
              width: 200
            },
            {
              title: '其中一把手调度次数',
              key: 'company_one_num',
              align: 'center',
              width: 200
            },
            {
              title: '参加本单位调度的市管干部人次数',
              key: 'company_cadres_num',
              align: 'center',
              width: 200
            },
            {
              title: '调度处级（中层干部）人次数',
              key: 'company_rank_num',
              align: 'center',
              width: 200
            }
          ]
        },
        {
          title: '梳理业务流程情况',
          align: 'center',
          children: [
            {
              title: '梳理排查业务数量',
              key: 'process_carding_num',
              align: 'center',
              width: 200
            },
            {
              title: '梳理发现存在问题漏洞的数量',
              key: 'process_problem_num',
              align: 'center',
              width: 200
            },
            {
              title: '其中：本单位自查发现问题漏洞数量（个）',
              key: 'process_company_num',
              align: 'center',
              width: 200
            },
            {
              title: '列入2020年体系建设重点任务的业务数量（个）',
              key: 'process_key_num',
              align: 'center',
              width: 200
            },
            {
              title: '2020年本单位财政预算项目专项数量（个）',
              key: 'process_finance_num',
              align: 'center',
              width: 200
            },
            {
              title: '2020年本单位财政预算项目总金额（万元）',
              key: 'process_finance_moeny',
              align: 'center',
              width: 200
            }
          ]
        },
        {
          title: '堵塞漏洞情况',
          align: 'center',
          children: [
            {
              title: '本单位提出内部防控（自我监督）措施数量（个）',
              key: 'process_supervise_num',
              align: 'center',
              width: 200
            },
            {
              title: '已完成问题漏洞堵塞的数量（个）',
              key: 'process_plugging_num',
              align: 'center',
              width: 200
            }
          ]
        },
        {
          title: '梳理完善政策规定情况',
          align: 'center',
          children: [
            {
              title: '梳理掌握的现有政策规定文件数量',
              key: 'policy_regulations_num',
              align: 'center',
              width: 200
            },
            {
              title: '修订完善的政策规定文件数量',
              key: 'policy_update_num',
              align: 'center',
              width: 200
            },
            {
              title: '新制定的政策规定文件数量',
              key: 'policy_new_num',
              align: 'center',
              width: 200
            },
            {
              title: '开展体系建设以来，取消、下放权力数（个）',
              key: 'policy_decentralization_num',
              align: 'center',
              width: 200
            }
          ]
        },
        {
          title: '系统建设情况',
          align: 'center',
          children: [
            {
              title: '现有信息系统数量（个）',
              key: 'system_now_num',
              align: 'center',
              width: 200
            },
            {
              title: '基于体系建设，新建系统平台数量（个）',
              key: 'system_platform_num',
              align: 'center',
              width: 200
            },
            {
              title: '其中：已建成数量（个）',
              key: 'system_success_num',
              align: 'center',
              width: 200
            },
            {
              title: '基于体系建设，改旧系统平台数量（个）',
              key: 'system_modify_num',
              align: 'center',
              width: 200
            },
            {
              title: '其中：已完成改旧数量（个）',
              key: 'system_update_low_num',
              align: 'center',
              width: 200
            },
            {
              title: '基于体系建设，已利旧系统平台数量（个）',
              key: 'system_utilize_low_num',
              align: 'center',
              width: 200
            },
            {
              title: '拟纳入市信息中心共建共享平台的业务数量',
              key: 'system_share_num',
              align: 'center',
              width: 200
            },
            {
              title: '已实现市区（县）上下贯通的系统平台数量（个）',
              key: 'system_city_num',
              align: 'center',
              width: 200
            },
            {
              title: '跨部门（非本单位）数据需求种类数量（个）',
              key: 'system_department_num',
              align: 'center',
              width: 200
            },
            {
              title: '数据需求涉及提供方单位数量（个）',
              key: 'system_provide_num',
              align: 'center',
              width: 200
            }
          ]
        },
        {
          title: '成效数据',
          align: 'center',
          children: [
            {
              title: '目前已避免发生问题的数量',
              key: 'data_avoid_num',
              align: 'center',
              width: 200
            },
            {
              title: '每年可节约资金或避免经济损失（万元）',
              key: 'data_save_num',
              align: 'center',
              width: 200
            },
            {
              title: '开展体系建设以来已挽回经济损失（万元）',
              key: 'data_system_num',
              align: 'center',
              width: 200
            },
            {
              title: '节约、避免、挽回经济损失的文字说明材料附件上传',
              key: 'data_file',
              align: 'center',
              slot: 'data_file',
              width: 200
            }
          ]
        },
        {
          title: '宣传推广情况',
          align: 'center',
          children: [
            {
              title: '市级以上媒体宣传推广次数',
              key: 'extension_num',
              align: 'center',
              width: 200
            },
            {
              title: '其中国家级次数',
              key: 'extension_national_num',
              align: 'center',
              width: 200
            },
            {
              title: '其中省级次数',
              key: 'extension_province_num',
              align: 'center',
              width: 200
            },
            {
              title: '其中市级次数',
              key: 'extension_city_num',
              align: 'center',
              width: 200
            },
            {
              title: '宣传报道支撑材料附件上传（链接、截图、文字等）',
              align: 'center',
              key: 'excel_impor',
              slot: 'excel_impor',
              width: 200
            }
          ]
        },
        {
          title: '备注',
          align: 'center',
          key: 'remark',
          width: 300
        },
        {
          title: '最后提报时间',
          align: 'center',
          key: 'update_time',
          width: 200
        },
        {
          title: '操作',
          slot: 'action',
          align: 'center',
          fixed: 'right',
          width: 100
        }
      ],
      data10: [],
      params: { pageNo: 1, pageSize: 10, totalRecord: 0 },
      aId: ''
    }
  },

  props: {

  },

  components: {

  },

  computed: {

  },

  methods: {
    format (time, format) {
      var t = new Date(time)
      var tf = function (i) { return (i < 10 ? '0' : '') + i }
      return format.replace(/yyyy|MM/g, function (a) {
        switch (a) {
          case 'yyyy':
            return tf(t.getFullYear())
          case 'MM':
            return tf(t.getMonth() + 1)
        }
      })
    },
    async init () {
      this.aId = this.$store.state.user.severUserInfo.data.company_id
      console.log(this.aId, 'adddd')
      var myDate = new Date()
      myDate.getFullYear() // 获取完整的年份(4位,1970-????)
      myDate.getMonth() // 获取当前月份(0-11,0代表1月)
      let y = myDate.getFullYear()
      let d = myDate.getMonth()
      if (d < 10) {
        d = '0' + d
      }
      let yd = y + '年' + d + '月'
      this.yf = yd
      this.month = y + '-' + d
      getZlShiZhiList().then(ret => {
        console.log(ret, 'ret@')
        this.data10 = ret.data.data.results
        this.data10.forEach(item => {
          if (item.excel_impor === '') {
            item.excel_impor = '暂无链接可下载'
          } if (item.data_file === '') {
            item.data_file = '暂无链接可下载'
          }
        })
        this.params.totalRecord = ret.data.data.totalRecord
      })
    },
    exportData () {
      let url = 'http://sstpw.tripln.top/wl/demo/commonExcelExport?id=25&companyId=' + this.aId
      window.location.href = url
    },
    show (row) {
      console.log(row, 'row!!!!!')
      this.$router.push({
        name: 'dataAcquisitionf',
        query: {
          para: row
        }
      })
    },
    pageAction (current) {
      let data = {
        pageNo: current,
        department_name: this.formInline.department_name,
        monthly: this.format(this.formInline.monthly, 'yyyy-MM'),
        company: this.formInline.company
      }
      getZlShiZhiList(data).then(ret => {
        this.data10 = ret.data.data.results
        this.data10.forEach(item => {
          if (item.excel_impor === '') {
            item.excel_impor = '暂无链接可下载'
          } if (item.data_file === '') {
            item.data_file = '暂无链接可下载'
          }
        })
        this.params.totalRecord = ret.data.data.totalRecord
      })
    },
    pSizeChange (val) {
      getZlShiZhiList({ pageSize: val }).then(ret => {
        this.data10 = ret.data.data.results
        this.data10.forEach(item => {
          if (item.excel_impor === '') {
            item.excel_impor = '暂无链接可下载'
          } if (item.data_file === '') {
            item.data_file = '暂无链接可下载'
          }
        })
        this.params.totalRecord = ret.data.data.totalRecord
      })
    },
    search () {
      console.log(this.formInline.monthly, 'the')
      if (this.formInline.monthly !== '') {
        const data = {
          department_name: this.formInline.department_name,
          monthly: this.format(this.formInline.monthly, 'yyyy-MM'),
          company: this.formInline.company
        }
        getZlShiZhiList(data).then(ret => {
          this.data10 = ret.data.data.results
          this.data10.forEach(item => {
            if (item.excel_impor === '') {
              item.excel_impor = '暂无链接可下载'
            } if (item.data_file === '') {
              item.data_file = '暂无链接可下载'
            }
          })
          this.params.totalRecord = ret.data.data.totalRecord
        })
      } else {
        const data = {
          department_name: this.formInline.department_name,
          monthly: this.month,
          company: this.formInline.company
        }
        getZlShiZhiList(data).then(ret => {
          this.data10 = ret.data.data.results
          this.data10.forEach(item => {
            if (item.excel_impor === '') {
              item.excel_impor = '暂无链接可下载'
            } if (item.data_file === '') {
              item.data_file = '暂无链接可下载'
            }
          })
          this.params.totalRecord = ret.data.data.totalRecord
        })
      }
    },
    download (row) {
      // console.log(row)
      window.location.href = row.excel_impor
    },
    downloadf (row) {
      // console.log(row)
      window.location.href = row.data_file
    }
  },

  watch: {

  },

  mounted () {
    this.init()
  }

}
</script>

<style scoped>

</style>
